<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('OKR信息列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">

<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 组织机构
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="管理部门"><i class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="deptId" name="deptId">
                    <input type="hidden" name="cycleId"   id="cycleId"/>
                    <div class="select-list">
                        <ul>

                            <li>
                                <label>用户姓名：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>内容描述：</label>
                                <input type="text" name="content"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:info:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:info:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:info:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:info:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info" id="expandAllBtn">
                    <i class="fa fa-exchange"></i> 展开/折叠
                </a>
<!--                <div class="btn-group"  th:each="cycle : ${cycleList}">-->
<!--                    <a class=""th:classappend="${cycle.cycleType == 0} ? 'btn btn-primary' : 'btn btn-info' "      th:text="${cycle.cycleName}"    th:value="${cycle.cycleName}"   th:onclick="'changeCycleType('+${cycle.cycleType}+')'"></a>-->
<!--                </div>-->
                <div class="btn-group">
                    <select class="form-control" data-style="btn-success"  id="cycleIdSelect"  th:onchange="changeCycleType()">
                        <optgroup th:label="#{okr.yearChoice}">
                            <div th:each="cycle : ${cycleList}">
                                <div th:if="${cycle.cycleType == 1}">
                                <span th:if="${cycle.status == 0}">
                                        <option th:value="${cycle.id}" selected="selected" th:text="${cycle.cycleName}"></option>
                                </span>
                                    <span th:if="${cycle.status == 1}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
                                </div>
                            </div>
                        </optgroup>
                        <optgroup th:label="#{okr.quarterChoice}">
                            <div th:each="cycle : ${cycleList}">
                                <div th:if="${cycle.cycleType == 0}">
                                <span th:if="${cycle.status == 0}">
                                        <option th:value="${cycle.id}" selected="selected" th:text="${cycle.cycleName}"></option>
                                </span>
                                    <span th:if="${cycle.status == 1}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
                                </div>
                            </div>
                        </optgroup>
                    </select>
                </div>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-tree-table" ></table>
            </div>
        </div>
    </div>
</div>


<th:block th:include="include :: footer" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var cycleFlag = [[${@permission.hasPermi('okr:cycle:useList')}]];
        var editFlag = [[${@permission.hasPermi('system:info:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:info:remove')}]];
        var rowTypeDatas = [[${@dict.getType('okr_row_type')}]];
        var scoreStarDatas = [[${@dict.getType('ork_fraction')}]];
        var statusDatas = [[${@dict.getType('row_status')}]];
        var priorityDatas = [[${@dict.getType('okr_level')}]];

        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185 });
            queryDeptTree();
        });

        var prefix = ctx + "system/info";
        $(function() {
             var options = {
                 code: "rowId",
                 parentCode: "parentId",
                 uniqueId: "id",
                 expandAll: true,
                 expandFirst: false,
                 url: prefix + "/list",
                 createUrl: prefix + "/add/{id}",
                 updateUrl: prefix + "/edit/{id}",
                 removeUrl: prefix + "/remove/{id}",
                 queryParams: queryParams,
                 search:true,
                 rowStyle:function(row,index){
                     alert(row+"___"+index);
                 },
                 modalName: "OKR信息",
                 columns: [{
                     field: 'selectItem',
                     radio: false
                 },

                     {
                         field: 'rowCode',
                         width: '10%',
                         title: '编号',
                         formatter: function(value, row, index) {
                             var rowNo = '';
                             if(row.rowType==0){
                                 rowNo = '<span>O'+value+'</span>';
                             }
                             else {
                                 rowNo = '<span>KR'+value+'</span>';
                             }
                             return rowNo;
                         }
                     },
                     {
                         title: 'OKR描述',
                         field: 'content',
                         width: '60%',
                         formatter: function (value, row, index) {
                             if (row.rowType == 0) {
                                 return '<H4>' + value + '</H4>';
                             } else {
                                 return '<p>' + value + '</p>';
                             }
                         }
                     },
                     {
                         field: 'userName',
                         width: '10%',
                         title: '用户'
                     },
                     {
                         field: 'deptName',
                         width: '15%',
                         title: '部门'
                     },
                     // {
                     //     field: 'rowType',
                     //     title: '类型',
                     //     width: '5%',
                     //     formatter: function(value, row, index) {
                     //         return $.table.selectDictLabel(rowTypeDatas, value);
                     //     }
                     // },
                     // {
                     //     field: 'confidenceStar',
                     //     title: '信心指数',
                     //     width: '5%',
                     //     formatter: function(value, row, index) {
                     //         return  '<span class="badge badge-success">'+value+'</span>';
                     //     }
                     // },
                     // {
                     //     field: 'scoreStar',
                     //     title: '目标评分',
                     //     width: '5%',
                     //     formatter: function(value, row, index) {
                     //         return $.table.selectDictLabel(scoreStarDatas, value);
                     //     }
                     // },
                     // {
                     //     field: 'process',
                     //     title: '目标进度',
                     //     width: '5%',
                     //     formatter: function(value, row, index) {
                     //         return  '<span class="badge badge-success">'+value+'</span>';
                     //     }
                     // },
                     {
                         field: 'operation',
                         title: '操作',
                         width: '5%',
                         formatter: function (value, row, index) {
                             let actions = [];
                             if (row.rowType == 0) { //判断如果是目标的话
                                 actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openViewFull(' + row.id + ')"><i class="fa fa-edit"></i>预览</a> ');
                             }
                             return actions.join('');
                         }
                     }]
             };
             $.treeTable.init(options);


             function queryParams(params) {
                 var search = $.table.queryParams(params);
                 search.userName = $("#userName").val();
                 return search;
             }


         });

        function openViewFull(id)
        {
            var url = "../okr/info/managerView/"+ id;
            $.modal.openFull("OKR预览", url);
            $.modal.disable();
        }

        function queryDeptTree()
        {
            var url = ctx + "system/dept/treeData";
            var options = {
                url: url,
                expandLevel: 2,
                check: {enable: false},
                showCheckBox: false,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                $("#deptId").val(treeNode.id);
                $.treeTable.search();
            }
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryDeptTree();
        });

        //OKR 周期切换
        function changeCycleType(type) {
            var cycleId = $("#cycleIdSelect").val();
            $("#cycleId").val(cycleId);
            $.treeTable.search();
        }
         </script>
</body>
</html>